/**
 * Copyright (C) 2021 - 2031 O-Cubes Co., Ltd.
 */

/****************************************************************
 *  @file    isp.h
 *  @brief   ISP header file
 *  @version v1.0
 *  @date    03. Apr. 2023
 ****************************************************************/

#ifndef __ISP_H__
#define __ISP_H__

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

#define ISP_DFT_UART_ID               DW_UART_0_ID

#define ISP_FLASH_PKG_HDR_ADDR        0x0
#define ISP_FLASH_PKG_HDR_SIZE        0x1000

#define ISP_SYNC_DATA                 0x7F
#define ISP_MAX_DATA_LEN              0x100
#define ISP_MAX_RETRANS_NUM           3
#define ISP_CMD_ACK                   0x79
#define ISP_CMD_NACK                  0x1F

#define ISP_CMD_GET_INFO              0x00
#define ISP_CMD_SET_BAUD              0x01

#define ISP_CMD_READ_MEMORY           0x11
#define ISP_CMD_READ_FLASH            0x12

#define ISP_CMD_RST                   0x22

#define ISP_CMD_WRITE_MEMORY          0x31
#define ISP_CMD_WRITE_FLASH           0x32

#define ISP_CMD_ERASE_FLASH           0x43

#define ISP_CMD_UPGRADE               0x51
#define ISP_CMD_GET_BOOT_PART         0x52
#define ISP_CMD_SWITCH_BOOT_PART      0x53

#define ISP_CMD_STOP                  0x60

#define ISP_CMD_FUNC_PTR(i) ((isp_cmd_func_set *)&glb_isp_func_set[i])

typedef enum {
	ISP_CHECKSUM_ERROR = 1,
	ISP_UNSUPPORTED_CMD,
	ISP_READ_FLASH_FAILED,
	ISP_WRITE_FLASH_FAILED,
	ISP_ERASE_FLASH_FAILED,
	ISP_INVALID_ADDRESS,
	ISP_IMAGE_CHECK_FAILED,
} isp_error_code;

typedef void (*cmd_func) (void);

typedef struct {
	uint8_t cmd_id;
	cmd_func func;
} isp_cmd_func_set;

void isp_start(void);

#ifdef __cplusplus
}
#endif

#endif /* __ISP_H__ */
